﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HCQ2_Model.Pay
{
    /// <summary>
    /// 获取订单数量请求参数
    /// </summary>
    public class GetOrderTotalParams : IOrderState, IPayUser,IValidatableObject
    {
        /// <summary>
        /// 【必填】购买人ID
        /// </summary>
        [Required(ErrorMessage = "购买人ID不能为空")]
        public string userid { get; set; }
        /// <summary>
        /// 【必填】订单状态;1(等待买家付款)、(2买家已付款)、4(交易成功)、5(交易关闭)、6(退款中)
        /// </summary>
        [Required(ErrorMessage ="订单状态不能为空")]
        public int? OrderState { get; set; }

        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            GetOrderTotalParams getOrderTotalParams = validationContext.ObjectInstance as GetOrderTotalParams;
            if (getOrderTotalParams != null)
            {
                if (!OrderStateEnum.CheckOrderState(getOrderTotalParams.OrderState.Value))
                {
                    yield return new ValidationResult("订单状态值无效，必须是：1(等待买家付款)、(2买家已付款)、4(交易成功)、5(交易关闭)、6(退款中)其中之一", new string[] { "OrderState" });
                }
            }
        }
    }
}
